window.onload = function() {
  //导航
  let navIcon = document.querySelector(".navIcon");
  let firstUl = document.querySelector(".myNav > ul");
  navIcon.addEventListener("click", function() {
    firstUl.classList.toggle("open");
  });
  firstUl.addEventListener("click", function(e) {
    if (e.target.nodeName == "A") {
      firstUl.classList.remove("open");
    }
  });
  firstUl.addEventListener("mouseleave", function(e) {
    firstUl.classList.remove("open");
  });

  // 产品
  const products = ["1.jpg","2.jpg","3.jpg","4.jpg"];
  let tmpHtml = "";
  for (let i = 0; i < 12; i++) {
    let index = Math.round(Math.random() * 3);
    console.log(index);
    tmpHtml += `
              <div class="item">
                <p>${ i + 1}</p>
                <img src="images/${products[index]}" width="90%" height="150" />
                <p>${products[index]}</>
              </div>
    `
  }
  let productsContain = document.querySelector(".products");
  productsContain.innerHTML = tmpHtml;
}
